const res = { name: '小花', city: '武汉', skills: ['js', 'css'] }

type Stu = typeof res

function fn(obj: Stu) {
  // 这里写 obj. 就会有提示
  obj.skills
}

fn(res)

type point = { x: number; y: number }
type P = keyof point
const a: P = 'y'

function fn1<Type>(value: Type): Type {
  return value
}

const num1 = fn1(10)

function useState<T>(value: T): [T, (val: T) => void] {
  const setVal = () => {}
  return [value, setVal]
}

function fn2<T>(v: T[]): T[] {
  console.log(v, 88)
  return v
}

// interface qq {
//   length: number
// }

type qq = string
function fn3<T extends qq>(value: T): T {
  return value
}
console.log(fn3('22222'), 99)

function fn4<T, Key extends keyof T>(obj: T, key: Key) {
  return obj[key]
}
console.log(fn4({ id: 2, name: 'jack' }, 'name'), 77)

interface MyArray {
  length: number
  push(n: number): void
  pop(): number
  reverse(): number[]
}

let obj: MyArray = {
  length: 22,
  push() {},
  pop() {
    return 1
  },
  reverse() {
    return [1]
  },
}

// const strs = ['a', 'b', 'c']
// // 鼠标放在 forEach 上查看类型
// strs.forEach

type OldP = {
  id: number
  name: string
}
type OldP2 = Partial<OldP>

type Props = {
  id: number
  children: number[]
}
type Props2 = Readonly<Props>
let pp: Props2 = { id: 1, children: [2] }
// pp.id = 333
console.log(pp.id, 555)

type Props3 = { id: string; name: string; children: number[] }
type PickProps = Pick<Props3, 'id' | 'name'>

export {}
